﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TireService.Data;
using DevExpress.Web.ASPxCallback;
using System.Web.Security;

namespace TireService.Web.View.OperatorView
{
    public partial class TireMount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TireServiceDB db = new TireServiceDB();

            BindTireMountList(db);
        }

        private void BindTireMountList(TireServiceDB db) 
        {
            //gvTireMount.DataSource = db.TireQuotationViews.Where(p => p.Approved != null & p.Mounted == null).ToList();
            //gvTireMount.DataBind();
        }

        /// <summary>
        /// Postback function that updates overview of need for tire mounting
        /// </summary>
        protected void gvTireMount_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
        {
            TireServiceDB db = new TireServiceDB();

            BindTireMountList(db);
        }

        /// <summary>
        /// Gridview function that runs when databinding
        /// </summary>
        protected void gvTireMount_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {

            //if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;

            //int servicetype = Convert.ToInt32(gvDayPlan.GetRowValuesByKeyValue(e.KeyValue, "ScheduleDetailTypeId"));

            //if (servicetype == (int)Shared.ScheduleDetailType.Available)
            //{
            //    e.Row.BackColor = System.Drawing.Color.White;
            //}
            //if (servicetype == (int)Shared.ScheduleDetailType.Blocked)
            //{
            //    e.Row.BackColor = System.Drawing.Color.Red;
            //}
            //if (servicetype == (int)Shared.ScheduleDetailType.ServiceDrive)
            //{
            //    // Get customerconfirmed value - based on that rows will be formated
            //    bool CustomerConfirmed = Convert.ToBoolean(gvDayPlan.GetRowValuesByKeyValue(e.KeyValue, "CustomerConfirmed"));

            //    if (CustomerConfirmed)
            //    {
            //        e.Row.BackColor = System.Drawing.Color.DarkGreen;
            //    }
            //    else
            //    {

            //        e.Row.BackColor = System.Drawing.Color.Orange;
            //    }
            //    bool WorkCompleted = Convert.ToBoolean(gvDayPlan.GetRowValuesByKeyValue(e.KeyValue, "WorkCompleted"));
            //    if (WorkCompleted)
            //    {
            //        e.Row.BackColor = System.Drawing.Color.DarkSlateBlue;
            //    }
            //}
        }

        /// <summary>
        /// Callback function that handles marking tireset quotation as mounted
        /// </summary>
        protected void callMarkTireSetAsMounted_Callback(object sender, CallbackEventArgs e)
        {
            //// Get value (quotation id)
            //Guid QuotationReferenceId = new Guid(e.Parameter);

            // HACK: Using CarId as key
            int CarId = Convert.ToInt32(e.Parameter);

            // Instantiate database
            TireServiceDB db = new TireServiceDB();

            // Get UserId
            Guid userid = new Guid(Membership.GetUser().ProviderUserKey.ToString());

            // TODO: Write code

            // Dispose database connection
            db.Dispose();
        }
    }
}